#for me
FTP=false
FTP2=false
UPLOAD=false
BUILD=true
LIST=false
RELEASE=false
DFLAGS="-version=USE_ZLIB -L-lz -d"
VERSION="-version=Wiki -version=Upload -version=BugTracking"
WARNING=true
#dmd or gdmd
DMD=dmd
PHOBOS=phobos
DOC=true
INST_DIR=sw
SVNCI=false
#export PATH=/usr/local/gcc-4.1/bin:$PATH
export PATH=/usr/local/gdc/bin:$PATH
while test $# -ge 1 ; do
  case "$1" in
   -upload)
    VERSION="-version=Upload"
    INST_DIR=upload
    shift;;
   -wiki)
    VERSION="-version=Wiki"
    INST_DIR=sw
    shift;;
   -sync)
    DFLAGS="$DFLAGS"
    INST_DIR=nazo
    shift;;
   -g)
    DMD=gdmd
    PHOBOS=gphobos
    shift;;
   -c)
    DFLAGS="$DFLAGS -O -release -L-O3"
    shift;;
   -i)
    DFLAGS="$DFLAGS -inline"
    shift;;
   -st)
    DFLAGS="$DFLAGS -L--strip-all"
    shift;;
   -f)
    FTP=true
    shift;;
   -f2)
    FTP2=true
    shift;;
   -u)
    STATIC=true
    UPLOAD=true
    DFLAGS="$DFLAGS -O -release -L-O3 -L--strip-all"
# -inline
#コンパイルのみ、最適化、リリースver
    shift;;
   -d)
    LIST=true
    shift;;
   -r)
    RELEASE=true
    DFLAGS="$DFLAGS -O -release -L-O3 -L--strip-all"
# -inline
    shift;;
   -rv)
    DFLAGS="$DFLAGS -O -release -L-O3 -L--strip-all"
# -inline
    shift;;
   -ut)
    DFLAGS="$DFLAGS -unittest"
    shift;;
   -s)
    DFLAGS="$DFLAGS -L-static"
    shift;;
   -dp)
    DFLAGS="$DFLAGS -debug=Parser"
    shift;;
   -db)
    DFLAGS="$DFLAGS -debug"
    shift;;
   -ci)
    SVNCI=true
    BUILD=false
    shift;;
   -p)
    DFLAGS="$DFLAGS -profile"
    shift;;
   -op)
    DFLAGS="$DFLAGS -O -release -profile"
    shift;;
   -v)
    DFLAGS="$DFLAGS -v"
    shift;;
   -nw)
    WARNING=false
    shift;;
   *)
    shift;;
  esac
done
if($SVNCI);then
  MESSAGE=`zenity --entry --title="SVNのチェックイン" --text="チェックインの詳細" --entry-text="some fixes"`
  svn ci -m "$MESSAGE"
fi
DFLAGS="$VERSION $DFLAGS"
if($WARNING);then
  DFLAGS="$DFLAGS -w"
fi
if($DOC);then
  if [ ! -d doc ];then
    mkdir doc
  fi
  DFLAGS="$DFLAGS nazo/*.ddoc -Dddoc/"
fi
if ($BUILD);then
  rm -f *.o
  $DMD -ofindex.cgi $DFLAGS nazo/*.d sw/*.d sw/*/*.d
fi
if ($RELEASE);then
  tar cjvf binary.tar.bz2 index.cgi *.txt *.css *.js *.pwd *.png
#  tar cf - index.cgi *.txt *.css *.js *.pwd *.png | 7za a -si -mx=9 binary.tar.7z
fi
if ($LIST);then
  echo "" > index.sw
  for file in nazo/*.d sw/*.d sw/*/*.d
  do
    tmp=${file##*/}
    echo "[dl[dt "$file"][dd [a 仕様書,doc/"${tmp%d}html"]]]" >> index.sw
  done
fi
if ($BUILD);then
  if [ -d /var/www/$INST_DIR ];then
    cp index.cgi /var/www/$INST_DIR
    cp -f index.cgi /var/www/${INST_DIR}_sync
    cp /var/www/$INST_DIR/index.cgi /var/www/$INST_DIR/nph-index.cgi
    rm -f /var/www/$INST_DIR/trace*
  fi
fi
if($FTP || $FTP2 || $RELEASE);then
#  tar cf - *.txt *.sh *.css *.js *.pwd nazo/*.d nazo/*.ddoc sw/*.d sw/*/*.d sw/*/*/*.d Makefile objs.macro *.svg *.png | 7za a -si -mx=9 source.tar.7z
  tar cjvf source.tar.bz2 *.txt *.sh *.css *.js *.pwd nazo/*.d nazo/*.ddoc sw/*.d sw/*/*.d Makefile objs.macro *.svg *.png
#  tar cf - *.txt *.sh *.css *.js *.pwd nazo/*.d nazo/*.ddoc sw/*.d sw/*/*.d sw/*/*/*.d Makefile objs.macro *.svg *.png | 7za a -si -tbzip2 source.tar.bz2
fi
if ($FTP);then
  lftp -u nazodane -e 'cd uploader;put source.tar.bz2;bye' ftp.isweb.infoseek.co.jp
fi
if ($FTP2);then
  lftp -u nazodane -e 'cd public_html;cd cgi-bin;put source.tar.bz2;bye' www4.pf-x.net
fi
if ($UPLOAD);then
  lftp -u nazodane -e 'cd public_html;cd cgi-bin;cd testing;put index.cgi;chmod 700 index.cgi;bye' www4.pf-x.net
fi
if ($RELEASE);then
  lftp -u nazodane -e 'cd public_html;cd structurewiki;put binary.tar.bz2;put source.tar.bz2;bye' www4.pf-x.net
fi
